package com.yicong.ants.ui.video;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.cchao.simplelib.core.Router;
import com.cchao.simplelib.ui.adapter.StatefulBindQuickAdapter;
import com.cchao.simplelib.ui.fragment.BaseStatefulFragment;
import com.yicong.ants.Constants;
import com.yicong.ants.R;
import com.yicong.ants.bean.video.FocusBean;
import com.yicong.ants.databinding.RecylerBinding;
import com.yicong.ants.ui.video.adapter.FocusListAdapter;

/**
 * 关注列表
 *
 * @author cchao
 */
public class FocusListFragment extends BaseStatefulFragment<RecylerBinding> {
    StatefulBindQuickAdapter<FocusBean> mAdapter;
    RecyclerView mRecycler;

    @Override
    protected int getLayoutId() {
        return R.layout.recyler;
    }

    @Override
    protected void initEventAndData() {
        initAdapter();
        onLoadData();
    }

    @Override
    protected void onLoadData() {
        mAdapter.loadPageData(1);
    }

    private void initAdapter() {
        String uid = getArguments().getString(Constants.Extra.Uid);
        mRecycler = mDataBind.recycler;
        mRecycler.setBackgroundResource(R.color.black);
        mRecycler.setLayoutManager(new LinearLayoutManager(mContext));
        mAdapter = new FocusListAdapter(this, mDisposable, uid);
        mAdapter.setOnItemClickListener((adapter1, view, position) -> {
            FocusBean focusBean = mAdapter.getItem(position);
            Router.turnTo(mContext, VideoProfileActivity.class)
                    .checkLogin(true)
                    .putExtra(Constants.Extra.Video_isFocus, "1".equals(focusBean.getIs_focus()))
                    .putExtra(Constants.Extra.Uid, focusBean.getFocus_id())
                    .start();

        });
        mAdapter.bindToRecyclerView(mRecycler);
        mRecycler.setAdapter(mAdapter);
        mAdapter.loadPageData(1);
    }
}

